package com.explorati.LinkedList.stack;

import com.explorati.stack.ArrayStack;

public class LinkedListStack<E> implements Stack<E> {

	private LinkedList<E> linkedList;

	public LinkedListStack() {
		this.linkedList = new LinkedList();
	}

	@Override
	public int getSize() {
		return linkedList.getSize();
	}

	@Override
	public boolean isEmpty() {
		return linkedList.isEmpty();
	}

	@Override
	public void push(E e) {
		linkedList.addFirst(e);
	}

	@Override
	public E peek() {
		return linkedList.getFirst();
	}

	@Override
	public E pop() {
		return linkedList.removeFirst();
	}

	@Override
	public String toString() {
		StringBuilder res = new StringBuilder();
		res.append("Stack: top ");
		res.append(linkedList);
		return res.toString();
	}

	public static void main(String[] args) {
		LinkedListStack<Integer> stack = new LinkedListStack<>();
		for (int i = 0; i < 5; i++) {
			stack.push(i);
			System.out.println(stack);
		}
		stack.pop();
		System.out.println(stack);
	}

}
